package au.edu.qut.bpm.genbinder.ui;

import java.awt.BorderLayout;
import java.util.List;
import java.util.Set;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import au.edu.qut.bpm.genbinder.models.Activity;
import au.edu.qut.bpm.genbinder.models.Case;
import au.edu.qut.bpm.genbinder.models.ConcreteEventLog;

public class CaseListPanel extends JPanel {
	private static final long serialVersionUID = -7125942201358845716L;
	public static double TIMETOPIXELS = 30;
	public static int ROWHEIGHT = 30;

	public static long TIMESTART;
	public static long TIMEEND;
	public static long TIMESHOWFROM;
	public static long ZEROBLOCK = 0L;

	public CaseListPanel() {
		this.setLayout(new BorderLayout());
	}

	public void showLog(ConcreteEventLog log) {
		this.removeAll();
		
		final JPanel listPanel = new JPanel();
		listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.PAGE_AXIS));

		TIMESTART = log.getLogArrival();

		TIMEEND = log.getLogEnd();

		TIMESHOWFROM = TIMESTART;
		
		List<Set<Activity>> violations = log.getLogViolatingActivities();

		for (Case oCase : log.getAbstractLog().getCases()) {
			CasePanel casePanel = new CasePanel(log, oCase, violations);
			listPanel.add(casePanel);
		}
		
		final JSlider slider = new JSlider();
		slider.setMinimum(0);
		slider.setMaximum(10000);
		slider.setValue(0);
		slider.addChangeListener(new ChangeListener() {
			@Override
			public void stateChanged(ChangeEvent arg0) {
				TIMESHOWFROM = TIMESTART +
						(long) (((double) slider.getValue() / (double) slider.getMaximum())
						* (double) (TIMEEND - TIMESTART));
				revalidate();
				repaint();
			}
		});

		this.add(slider, BorderLayout.NORTH);
		this.add(listPanel, BorderLayout.CENTER);
		

		this.revalidate();
		this.repaint();
	}

}
